package cn.lanqiao.bigDate.service.sys.impl;

import java.util.Set;
import org.springframework.stereotype.Service;
import cn.lanqiao.bigDate.mapper.sys.LoginMapper;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import cn.lanqiao.bigDate.service.sys.LoginService;
import java.util.concurrent.TimeUnit;

@Service
public class LoginServiceImpl implements LoginService{

	@Autowired
	private RedisTemplate redisTemplate;

	@Autowired
	private LoginMapper loginMapper;

	public Set<String> getMenuList(String loginName){
		Set<String> urlSet= (Set<String>) redisTemplate.opsForValue().get(loginName);
		if(urlSet==null||urlSet.size()==0){
			urlSet=loginMapper.getMenuList(loginName);
			redisTemplate.opsForValue().set(loginName,urlSet);
			redisTemplate.expire(loginName,15,TimeUnit.MINUTES);
		}
		return urlSet;
	}

	public boolean login(String loginName,String password,String loginIp){
		return loginMapper.login(loginName,password,loginIp)==1?true:false;
	}

	public void updateMenuList(String loginName){
		if(redisTemplate.hasKey(loginName)){
			redisTemplate.opsForValue().set(loginName,loginMapper.getMenuList(loginName));
		}
	}

}